package com.whlilong.jxc.productmanager.editor;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.nebula.widgets.datechooser.DateChooserCombo;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;

import com.swtdesigner.ResourceManager;
import com.whlilong.jxc.abstracteditor.AbstractEditor;
import com.whlilong.jxc.db.DbManager;
import com.whlilong.jxc.model.Bookbill;
import com.whlilong.jxc.model.Purcharsbook;
import com.whlilong.jxc.model.Selldetail;
import com.whlilong.jxc.model.Sellmain;
import com.whlilong.jxc.model.Yginfo;
import com.whlilong.jxc.print.IconSource;
import com.whlilong.jxc.print.PDocument;
import com.whlilong.jxc.print.PHLine;
import com.whlilong.jxc.print.PTableBoxProvider;
import com.whlilong.jxc.print.PTextBox;
import com.whlilong.jxc.print.PVSpace;
import com.whlilong.jxc.print.PrintPreview;
import com.whlilong.jxc.print.SWTPTable;
import com.whlilong.jxc.sys.ExtentionInfo;
import com.whlilong.jxc.sys.SetTableColColorListener;
import com.whlilong.jxc.ui.provider.SellMainTableContentProvider;
import com.whlilong.jxc.ui.provider.SellMainTableLableProvider;
import com.whlilong.jxc.ui.provider.SelldetailTableContentProvider;
import com.whlilong.jxc.ui.provider.SelldetailTableLableProvider;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.nebula.widgets.cdatetime.CDateTime;
import org.eclipse.nebula.widgets.cdatetime.CDT;

public class SellBillEditor extends AbstractEditor {

	private Composite container;
	private CTabFolder tabFolder;
	private CTabItem tabItem;
	private Composite composite;
	private Label timeLabel;
	private Label label;
	private Label sellidLabel;
	private Text textSellid;
	private Label labelStaff;
	private Label labelBase;
	private Combo comboBase;
	private Button billSearch;
	private Composite compositeUp;
	private CTabItem tabItemDetail;
	private Composite compositeDown;
	private Table tableBill;
	private TableViewer tableViewerBill;
	private Composite compositeDetail;
	private Text text_sellid;
	private Label label_base;
	private Label label_barcode;
	private Text text_barcode;
	private Label label_goodsid;
	private Text text_goodsid;
	private Label label_goodsname;
	private Text text_goodsname;
	private Combo combo_base;
	private Table tableDetail;
	private TableViewer tableViewerDetail;
	private Composite compositeDetailUp;
	private Composite compositeDetailDown;
	private Button detailSearch;
	private List<Yginfo> staff = new ArrayList<Yginfo>();
	private List<Sellmain> billList = new ArrayList<Sellmain>();
	private List<Selldetail> detailList = new ArrayList<Selldetail>();
	private static final SimpleDateFormat df = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm:ss");
	private static final SimpleDateFormat df1 = new SimpleDateFormat(
			"yyyy-MM-dd");
	private Combo comboStaff;
	private Combo combo_staff;
	private CDateTime dateTime;
	private CDateTime dateTime_1;
	private CDateTime dateTime_2;
	private CDateTime dateTime_3;

	public SellBillEditor() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @wbp.parser.entryPoint
	 */
	public Control createGroupText(Composite parent) {

		container = new Composite(parent, SWT.NONE);
		final GridLayout gl_container = new GridLayout(1, false);
		container.setLayout(gl_container);

		createBook(container);

		initial();
		// setInput();

		return container;

	}

	private void initial() {
		Date date = new Date();
		String mode = df1.format(date);
		String begin = mode + " 00:00:00";
		String stop = mode + " 23:59:59";
		try {
			dateTime.setSelection(df.parse(begin));
			dateTime_1.setSelection(df.parse(stop));
			dateTime_2.setSelection(df.parse(begin));
			dateTime_3.setSelection(df.parse(stop));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		staff = ExtentionInfo.getInstance().getStaffInfoList();
		comboStaff.add("未签名");
		combo_staff.add("未签名");
		for (int i = 0; i < staff.size(); i++) {
			comboStaff.add(staff.get(i).getYgname());
			combo_staff.add(staff.get(i).getYgname());
		}

	}

	private void createBook(Composite parent) {
		tabFolder = new CTabFolder(parent, SWT.BORDER);
		tabFolder.setSimple(false);
		tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1,
				1));
		tabFolder.setSelectionBackground(Display.getCurrent().getSystemColor(
				SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));

		createBillItem(tabFolder);
		createDetailItem(tabFolder);

		addListener();

	}

	private void createDetailItem(CTabFolder parent) {
		// TODO create Detail Item
		tabItemDetail = new CTabItem(parent, SWT.NONE);
		tabItemDetail.setText("销售明细");

		compositeDetail = new Composite(parent, SWT.NONE);
		tabItemDetail.setControl(compositeDetail);
		compositeDetail.setLayout(new GridLayout(1, false));

		compositeDetailUp = new Composite(compositeDetail, SWT.BORDER);
		compositeDetailUp.setLayout(new GridLayout(6, false));
		compositeDetailUp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
				true, false, 1, 1));

		Label labelTime = new Label(compositeDetailUp, SWT.NONE);
		labelTime.setBounds(0, 0, 61, 17);
		labelTime.setText("时间：");

		dateTime_2 = new CDateTime(compositeDetailUp, CDT.BORDER
				| CDT.CLOCK_24_HOUR | CDT.COMPACT | CDT.DROP_DOWN
				| CDT.BUTTON_LEFT);
		dateTime_2.setNullText("0000-00-00 00:00:00");
		dateTime_2.setPattern("yyyy-MM-dd HH:mm:ss");
		GridData gd_dateTime_2 = new GridData(SWT.LEFT, SWT.CENTER, false,
				false, 1, 1);
		gd_dateTime_2.widthHint = 145;
		dateTime_2.setLayoutData(gd_dateTime_2);

		Label labeltime = new Label(compositeDetailUp, SWT.NONE);
		labeltime.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false,
				false, 1, 1));
		labeltime.setAlignment(SWT.CENTER);
		labeltime.setText("至");

		dateTime_3 = new CDateTime(compositeDetailUp, CDT.BORDER
				| CDT.CLOCK_24_HOUR | CDT.COMPACT | CDT.DROP_DOWN
				| CDT.BUTTON_LEFT);
		dateTime_3.setNullText("0000-00-00 00:00:00");
		GridData gd_dateTime_3 = new GridData(SWT.LEFT, SWT.CENTER, false,
				false, 1, 1);
		gd_dateTime_3.widthHint = 145;
		dateTime_3.setLayoutData(gd_dateTime_3);
		dateTime_3.setPattern("yyyy-MM-dd HH:mm:ss");
		new Label(compositeDetailUp, SWT.NONE);

		detailSearch = new Button(compositeDetailUp, SWT.NONE);
		GridData gd_detailSearch = new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1);
		gd_detailSearch.widthHint = 80;
		detailSearch.setLayoutData(gd_detailSearch);
		detailSearch.setText("查询");

		Label label_sellid = new Label(compositeDetailUp, SWT.NONE);
		label_sellid.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));
		label_sellid.setText("销售单号：");

		text_sellid = new Text(compositeDetailUp, SWT.BORDER);
		GridData gd_text_sellid = new GridData(SWT.FILL, SWT.CENTER, false,
				false, 1, 1);
		gd_text_sellid.widthHint = 120;
		text_sellid.setLayoutData(gd_text_sellid);
		Label label_staff = new Label(compositeDetailUp, SWT.NONE);
		label_staff.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));
		label_staff.setBounds(0, 0, 61, 17);
		label_staff.setText("营业员：");

		combo_staff = new Combo(compositeDetailUp, SWT.READ_ONLY);
		combo_staff.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
				false, 1, 1));

		label_base = new Label(compositeDetailUp, SWT.NONE);
		label_base.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));
		label_base.setText("仓库：");

		combo_base = new Combo(compositeDetailUp, SWT.READ_ONLY);
		combo_base.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
				false, 1, 1));

		label_barcode = new Label(compositeDetailUp, SWT.NONE);
		label_barcode.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));
		label_barcode.setText("商品条码：");

		text_barcode = new Text(compositeDetailUp, SWT.BORDER);
		text_barcode.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
				false, 1, 1));

		label_goodsid = new Label(compositeDetailUp, SWT.NONE);
		label_goodsid.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));
		label_goodsid.setText("商品编号：");

		text_goodsid = new Text(compositeDetailUp, SWT.BORDER);
		text_goodsid.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
				false, 1, 1));

		label_goodsname = new Label(compositeDetailUp, SWT.NONE);
		label_goodsname.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER,
				false, false, 1, 1));
		label_goodsname.setText("商品名称：");

		text_goodsname = new Text(compositeDetailUp, SWT.BORDER);
		text_goodsname.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
				false, 1, 1));

		createDetailTable(compositeDetail);

	}

	private void createBillItem(CTabFolder parent) {

		tabItem = new CTabItem(parent, SWT.NONE);
		tabItem.setImage(ResourceManager.getPluginImage("com.whlilong.jxc",
				"icons/brand1.gif"));
		tabItem.setText("销售单据查询");

		tabFolder.setSelection(tabItem);

		composite = new Composite(parent, SWT.NONE);
		tabItem.setControl(composite);
		composite.setLayout(new GridLayout(1, false));

		compositeUp = new Composite(composite, SWT.BORDER);
		compositeUp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
				false, 1, 1));
		compositeUp.setLayout(new GridLayout(6, false));

		timeLabel = new Label(compositeUp, SWT.NONE);
		timeLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));
		timeLabel.setText("时间：");

		dateTime = new CDateTime(compositeUp, CDT.BORDER | CDT.CLOCK_24_HOUR
				| CDT.COMPACT | CDT.DROP_DOWN);
		dateTime.setNullText("0000-00-00 00:00:00");
		GridData gd_dateTime = new GridData(SWT.LEFT, SWT.CENTER, false, false,
				1, 1);
		gd_dateTime.widthHint = 145;
		dateTime.setLayoutData(gd_dateTime);
		dateTime.setPattern("yyyy-MM-dd HH:mm:ss");

		label = new Label(compositeUp, SWT.NONE);
		label.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false,
				1, 1));
		label.setText("至");

		dateTime_1 = new CDateTime(compositeUp, CDT.BORDER | CDT.CLOCK_24_HOUR
				| CDT.COMPACT | CDT.DROP_DOWN | CDT.BUTTON_LEFT);
		dateTime_1.setNullText("0000-00-00 00:00:00");
		GridData gd_dateTime_1 = new GridData(SWT.LEFT, SWT.CENTER, false,
				false, 1, 1);
		gd_dateTime_1.widthHint = 145;
		dateTime_1.setLayoutData(gd_dateTime_1);
		dateTime_1.setPattern("yyyy-MM-dd HH:mm:ss");
		new Label(compositeUp, SWT.NONE);

		billSearch = new Button(compositeUp, SWT.NONE);
		GridData gd_billSearch = new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1);
		gd_billSearch.widthHint = 80;
		billSearch.setLayoutData(gd_billSearch);
		billSearch.setText("查询");
		billSearch.setFocus();

		sellidLabel = new Label(compositeUp, SWT.NONE);
		sellidLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));
		sellidLabel.setText("销售单号：");

		textSellid = new Text(compositeUp, SWT.BORDER);
		GridData gd_textSellid = new GridData(SWT.LEFT, SWT.CENTER, false,
				false, 1, 1);
		gd_textSellid.widthHint = 140;
		textSellid.setLayoutData(gd_textSellid);

		labelStaff = new Label(compositeUp, SWT.NONE);
		labelStaff.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));
		labelStaff.setText("营业员：");

		comboStaff = new Combo(compositeUp, SWT.READ_ONLY);
		comboStaff.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
				false, 1, 1));

		labelBase = new Label(compositeUp, SWT.NONE);
		labelBase.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));
		labelBase.setText("仓库：");

		comboBase = new Combo(compositeUp, SWT.READ_ONLY);

		createBillTable(composite);

	}

	private void createDetailTable(Composite compositeDetail2) {
		// TODO create sell Detail tabele
		compositeDetailDown = new Composite(compositeDetail, SWT.BORDER);
		compositeDetailDown.setLayout(new GridLayout(1, false));
		compositeDetailDown.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
				true, true, 1, 1));

		tableViewerDetail = new TableViewer(compositeDetailDown, SWT.BORDER
				| SWT.FULL_SELECTION);
		tableViewerDetail.setUseHashlookup(true);
		tableDetail = tableViewerDetail.getTable();
		tableDetail.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true,
				1, 1));
		// 设置行高
		tableDetail.addListener(SWT.MeasureItem, new Listener() {
			public void handleEvent(Event event) {

				event.height = 20;
			}
		});
		createColumn("ID", null, null, tableViewerDetail);
		createColumn("商品条码", null, null, tableViewerDetail);
		createColumn("商品编号", null, null, tableViewerDetail);
		createColumn("商品名称", null, null, tableViewerDetail);
		createColumn("销售单号", null, null, tableViewerDetail);
		createColumn("销售日期", null, null, tableViewerDetail);
		createColumn("营业员", null, null, tableViewerDetail);
		createColumn("金额", null, null, tableViewerDetail);
		createColumn("折扣金额", null, null, tableViewerDetail);
		createColumn("折扣方式", null, null, tableViewerDetail);
		createColumn("数量", null, null, tableViewerDetail);
		createColumn("零售价格", null, null, tableViewerDetail);
		createColumn("销售价格", null, null, tableViewerDetail);
		createColumn("销售方式", null, null, tableViewerDetail);
		createColumn("仓库", null, null, tableViewerDetail);

		tableDetail.setHeaderVisible(true);
		tableDetail.setLinesVisible(true);

		tableViewerDetail
				.setContentProvider(new SelldetailTableContentProvider());
		tableViewerDetail.setLabelProvider(new SelldetailTableLableProvider());

		tableViewerDetail.setInput(detailList);
		tableDetail.addListener(SWT.EraseItem, new SetTableColColorListener(
				tableDetail));
		tableDetail.select(0);
		tableDetail.setFocus();
	}

	private void createBillTable(Composite composite2) {
		// TODO create sellBill table
		compositeDown = new Composite(composite2, SWT.BORDER);
		compositeDown.setLayout(new GridLayout(1, false));
		compositeDown.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false,
				true, 1, 1));

		tableViewerBill = new TableViewer(compositeDown, SWT.BORDER
				| SWT.FULL_SELECTION);
		tableViewerBill.setUseHashlookup(true);
		tableBill = tableViewerBill.getTable();
		tableBill.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1,
				1));
		// 设置行高
		tableBill.addListener(SWT.MeasureItem, new Listener() {
			public void handleEvent(Event event) {

				event.height = 20;
			}
		});
		createColumn("ID", null, null, tableViewerBill);
		createColumn("销售单号", null, null, tableViewerBill);
		createColumn("销售日期", null, null, tableViewerBill);
		createColumn("营业员", null, null, tableViewerBill);
		createColumn("合计金额", null, null, tableViewerBill);
		createColumn("折扣金额", null, null, tableViewerBill);
		createColumn("实付金额", null, null, tableViewerBill);
		createColumn("数量", null, null, tableViewerBill);
		createColumn("找零金额", null, null, tableViewerBill);
		createColumn("仓库", null, null, tableViewerBill);

		tableBill.setHeaderVisible(true);
		tableBill.setLinesVisible(true);

		tableViewerBill.setContentProvider(new SellMainTableContentProvider());
		tableViewerBill.setLabelProvider(new SellMainTableLableProvider());

		tableViewerBill.setInput(billList);
		tableBill.addListener(SWT.EraseItem, new SetTableColColorListener(
				tableBill));
		tableBill.select(0);
		tableBill.setFocus();
	}

	protected void setSellid(String sellid) {
		// TODO 双击单据项，打开明细表并在销售单号文本框中填入销售单号
		text_sellid.setText(sellid);
		dateTime_2.setSelection(null);
		dateTime_3.setSelection(null);
	}

	protected void billSearch() {
		// TODO 单据查询
		billList.clear();
		Date begin = dateTime.getSelection();
		Date stop = dateTime_1.getSelection();
		try {
			if (begin == null)
				begin = df.parse(dateTime.getNullText());
			if (stop == null)
				stop = df.parse(dateTime_1.getNullText());
		} catch (ParseException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		if (begin.after(stop)) {
			MessageDialog.openWarning(null, "警告", "时间段设置错误,自动设置为当前系统时间!");
			dateTime_1.setSelection(new Date());
			return;
		}
		List<Sellmain> blList = ExtentionInfo.getInstance().getSellmain();
		for (int i = 0; i < blList.size(); i++) {
			Date selldate = null;
			try {
				selldate = df.parse(df.format(blList.get(i).getSelldate()));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if (selldate.after(begin) && selldate.before(stop)
					|| selldate.equals(begin) || selldate.equals(stop)) {
				billList.add(blList.get(i));
			}
		}

		billList = billSearchCondition(billList);

		tableViewerBill.setInput(billList);

	}

	private List billSearchCondition(List<Sellmain> list) {
		// TODO 时间段内条件查询
		String sellid = textSellid.getText();
		int i = comboStaff.getSelectionIndex();
		String base = comboBase.getText();
		if (!sellid.equals("") && sellid != null) {
			for (int k = 0; k < list.size(); k++) {
				if (!list.get(k).getSellid().equals(sellid)) {
					list.remove(k);
					k--;
				}
			}
		}
		if (i > 0) {
			for (int k = 0; k < list.size(); k++) {
				if (!list.get(k).getStaff().equals(staff.get(k).getYgname())) {
					list.remove(k);
					k--;
				}

			}
		}
		return list;

	}

	protected void detailSearch() {
		// TODO 明细查询
		detailList.clear();
		Date begin = dateTime_2.getSelection();
		Date stop = dateTime_3.getSelection();
		try {
			if (begin == null)
				begin = df.parse(dateTime_2.getNullText());
			if (stop == null)
				stop = df.parse(dateTime_3.getNullText());
		} catch (ParseException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		if (begin.after(stop)) {
			MessageDialog.openWarning(null, "警告", "时间段设置错误,自动设置为当前系统时间!");
			dateTime_3.setSelection(new Date());
			return;
		}
		List<Selldetail> dtlList = ExtentionInfo.getInstance().getSelldetail();
		for (int i = 0; i < dtlList.size(); i++) {
			Date selldate = null;
			try {
				selldate = df.parse(df.format(dtlList.get(i).getSelldate()));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if (selldate.after(begin) && selldate.before(stop)
					|| selldate.equals(begin) || selldate.equals(stop)) {
				detailList.add(dtlList.get(i));
			}
		}
		detailList = detailSearchCondition(detailList);
		tableViewerDetail.setInput(detailList);

	}

	private List<Selldetail> detailSearchCondition(List<Selldetail> list) {
		// TODO 时间段内条件查询
		String sellid = text_sellid.getText();
		int i = combo_staff.getSelectionIndex();
		String base = combo_base.getText();
		String barcode = text_barcode.getText();
		String goodsid = text_goodsid.getText();
		String goodsname = text_goodsname.getText();
		if (!sellid.equals("") && sellid != null) {
			for (int k = 0; k < list.size(); k++) {
				if (!list.get(k).getSellid().equals(sellid)) {
					list.remove(k);
					k--;
				}
			}
		}
		if (i > 0) {
			for (int k = 0; k < list.size(); k++) {
				if (!list.get(k).getStaff().equals(staff.get(k).getYgname())) {
					list.remove(k);
					k--;
				}

			}
		}
		if (!barcode.equals("") && barcode != null) {
			for (int k = 0; k < list.size(); k++) {
				if (!list.get(k).getBarcode().equals(barcode)) {
					list.remove(k);
					k--;
				}
			}

		}
		if (!goodsid.equals("") && goodsid != null) {
			for (int k = 0; k < list.size(); k++) {
				if (!list.get(k).getGoodsid().equals(goodsid)) {
					list.remove(k);
					k--;
				}
			}

		}
		if (!goodsname.equals("") && goodsname != null) {
			for (int k = 0; k < list.size(); k++) {
				if (!list.get(k).getGoodsname().equals(goodsname)) {
					list.remove(k);
					k--;
				}
			}

		}

		return list;

	}

	private void addListener() {
		// TODO 监听事件
		detailSearch.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				detailSearch();
			}
		});

		billSearch.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				billSearch();
			}
		});
		tableBill.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDoubleClick(MouseEvent e) {
				Point pt = new Point(e.x, e.y);
				final TableItem item = tableBill.getItem(pt);
				if (item != null) {
					tabFolder.setSelection(tabItemDetail);
					Sellmain sellmain = (Sellmain) item.getData();
					String sellid = sellmain.getSellid();
					int[] idBuffer = { 0 };
					Object[] idObject = { sellid };
					List<Selldetail> detaillist = (List) DbManager
							.getInstance()
							.search(
									"com.whlilong.jxc.editor.getSelldetail.getsellid",
									idBuffer, idObject);
					tableViewerDetail.setInput(detaillist);
					setSellid(sellid);

				}
			}
		});

	}

	@Override
	public void addInfo() {
		// TODO Auto-generated method stub

	}

	@Override
	public void create() {
		// TODO Auto-generated method stub

	}

	@Override
	public void delete() {
		// TODO Auto-generated method stub

	}

	@Override
	public void print() {
		// TODO Auto-generated method stub
		final PDocument doc = new PDocument("print");

		PTextBox t;

		t = new PTextBox(doc);

		t.setText("武汉立隆客商信息");

		new PVSpace(doc, 0.5);
		new PHLine(doc, 0.02, SWT.COLOR_RED);
		new PVSpace(doc, 0.5);

		// create the table
		SWTPTable swttable = new SWTPTable(doc);
		swttable.setTable(tableBill);
		swttable.setBoxProvider(new PTableBoxProvider());

		PrintPreview pr = new PrintPreview(null, "信息打印", IconSource
				.getImage("print"), doc);
		pr.onPrint();
	}

	@Override
	public void refresh() {
		// TODO Auto-generated method stub

	}

	@Override
	public void save() {
		// TODO Auto-generated method stub

	}

	@Override
	public void search() {
		// TODO Auto-generated method stub

	}

	@Override
	public void searchByCondition() {
		// TODO Auto-generated method stub

	}

	@Override
	public void preprint() {
		// TODO Auto-generated method stub
		final PDocument doc = new PDocument("print");

		PTextBox t;

		t = new PTextBox(doc);

		t.setText("武汉立隆客商信息");

		new PVSpace(doc, 0.5);
		new PHLine(doc, 0.02, SWT.COLOR_RED);
		new PVSpace(doc, 0.5);

		// create the table
		SWTPTable swttable = new SWTPTable(doc);
		swttable.setTable(tableBill);
		swttable.setBoxProvider(new PTableBoxProvider());

		PrintPreview pr = new PrintPreview(null, "信息打印", IconSource
				.getImage("print"), doc);
		pr.open();
	}
}
